{template 'web/_header'}
{template 'tabs'}

{if $operation=='display'}
<div class="panel panel-info">
    <div class="panel-heading">筛选</div>
    <div class="panel-body">
        <form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">
            <input type="hidden" name="c" value="site" />
            <input type="hidden" name="a" value="entry" />
            <input type="hidden" name="m" value="sz_yi" />
            <input type="hidden" name="do" value="plugin" />
            <input type="hidden" name="p" value="commission" />
            <input type="hidden" name="method" value="agent" />
            <input type="hidden" name="op" value="display" />
            <div class="form-group">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">成为分销商时间</label>
                    <div class="col-sm-7 col-lg-9 col-xs-12">
                        <div class="col-sm-2">
                            <label class='radio-inline'>
                                <input type='radio' value='0' name='searchtime' {if $_GPC['searchtime']=='0'}checked{/if}>不搜索
                            </label> 
                             <label class='radio-inline'>
                                <input type='radio' value='1' name='searchtime' {if $_GPC['searchtime']=='1'}checked{/if}>搜索
                            </label>
                     </div>
                        {php echo tpl_form_field_daterange('time', array('starttime'=>date('Y-m-d H:i', $starttime),'endtime'=>date('Y-m-d  H:i', $endtime)),true);}
                    </div>
                </div>
                <div class="form-group">
                <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">ID</label>
                <div class="col-sm-8 col-lg-9 col-xs-12">
                    <input type="text" class="form-control"  name="mid" value="{$_GPC['mid']}"/> 
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">会员信息</label>
                <div class="col-sm-8 col-lg-9 col-xs-12">
                    <input type="text" class="form-control"  name="realname" value="{$_GPC['realname']}" placeholder='可搜索昵称/名称/手机号'/> 
                </div>
            </div>
         <div class="form-group">
                <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">是否关注</label>
                <div class="col-sm-8 col-lg-9 col-xs-12">
                       <select name='followed' class='form-control'>
                        <option value=''></option>
                        <option value='0' {if $_GPC['followed']=='0'}selected{/if}>未关注</option>
                        <option value='1' {if $_GPC['followed']=='1'}selected{/if}>已关注</option>
                        <option value='2' {if $_GPC['followed']=='2'}selected{/if}>取消关注</option>
                    </select>
                </div>
            </div>
                   <div class="form-group">
                <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">推荐人</label>
                <div class="col-sm-3">
                    <select name='parentid' class='form-control'>
                        <option value=''></option>
                        <option value='0' {if $_GPC['parentid']=='0'}selected{/if}>总店</option>
                    </select>
                </div>
                 <div class="col-sm-6">
                    <input type="text"  class="form-control" name="parentname" value="{$_GPC['parentname']}" placeholder='推荐人昵称/姓名/手机号'/> 
                </div>
            </div>
             <div class="form-group">
                <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">分销商等级</label>
                <div class="col-sm-8 col-lg-9 col-xs-12">
                    <select name='agentlevel' class='form-control'>
                        <option value=''></option>
                         {loop $agentlevels $level}
                        <option value='{$level['id']}' {if $_GPC['agentlevel']==$level['id']}selected{/if}>{$level['levelname']}</option>
                        {/loop}
                    </select>
                </div>
            </div>
              <div class="form-group">
                <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">状态</label>
                 <div class="col-sm-4">
                    <select name='status' class='form-control'>
                        <option value=''>审核状态</option>
                        <option value='0' {if $_GPC['status']=='0'}selected{/if}>未审核</option>
                        <option value='1' {if $_GPC['status']=='1'}selected{/if}>已审核</option>
                    </select>
                       </div>
                      <div class="col-sm-4">
                       <select name='agentblack' class='form-control'>
                        <option value=''>黑名单状态</option>
                        <option value='0' {if $_GPC['agentblack']=='0'}selected{/if}>否</option>
                        <option value='1' {if $_GPC['agentblack']=='1'}selected{/if}>是</option>
                    </select>
                </div>
 
            </div>
<div class="form-group">
                <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"></label>
                <div class="col-sm-8 col-lg-9 col-xs-12">
                       <button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
			<input type="hidden" name="token" value="{$_W['token']}" />
                       {ifp 'commission.agent.export'}   
                        <button type="submit" name="export" value="1" class="btn btn-primary">导出 Excel</button>
                        {/if}
                </div>
            </div>    
        </form>
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-heading">总数：{$total}</div>
    <div class="panel-body">
        <table class="table table-hover table-responsive">
            <thead class="navbar-inner" >
                <tr>
                     <th style='width:80px;'>会员ID</th>
                     <th style='width:120px;'>推荐人</th>
                    <th style='width:120px;'>粉丝</th>
                    <th style='width:110px;'>姓名<br/>手机号码</th>
                    <th style='width:80px;'>分销等级</th>
                    <th style='width:80px;'>点击数</th>
                    <th style='width:100px;'>累计佣金<br/>打款佣金</th>
                    <th style='width:120px;'>下级分销商</th>
                    <th style='width:100px;'>状态{ifp 'commission.agent.check'}<br/>（点击审核){/if}</th>
                    <th style='width:200px;'>时间</th>
                     <th style='width:70px'>关注</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {loop $list $row}
                <tr>
                      <td>{$row['id']}</td>
                      <td  {if !empty($row['agentid'])}title='ID: {$row['agentid']}'{/if}>
                           {if empty($row['agentid'])}
                                 {if $row['isagent']==1}
				      <label class='label label-primary'>总店</label>
				      {else}
				       <label class='label label-default'>暂无</label>
				      {/if}
                          {else}
                          <img src='{$row['parentavatar']}' style='width:30px;height:30px;padding1px;border:1px solid #ccc' /> {$row['parentname']}
                          {/if}
                      </td>
                    <td> 
                    {if !empty($row['avatar'])}
                         <img src='{$row['avatar']}' style='width:30px;height:30px;padding1px;border:1px solid #ccc' />
                       {/if}
                       {if empty($row['nickname'])}未更新{else}{$row['nickname']}{/if}
                        
                    </td>
                    
                    <td>{$row['realname']} <br/> {$row['mobile']}</td>
<td>{if empty($row['levelname'])} {php echo empty($this->set['levelname'])?'普通等级':$this->set['levelname']}{else}{$row['levelname']}{/if}</td>
                    <td>{$row['clickcount']}</td>
                    <td>{$row['commission_total']}<br/>{$row['commission_pay']}</td>
                    <td>
                        总计：{$row['levelcount']} 人
                        {if $level>=1 && $row['level1']>0}<br/>一级：{$row['level1']} 人{/if}
                        {if $level>=2  && $row['level2']>0}<br/> 二级：{$row['level2']} 人{/if}
                        {if $level>=3  && $row['level3']>0}<br/>三级：{$row['level3']} 人{/if}</td>
                    <td>
                        {if $row['status']==0}
                                {if $row['agentblack']==1}
                                  <span class="label label-default" style='color:#fff;background:black'>黑名单</span>
                                {else}
                                  
                                   {ifp 'commission.agent.check'}
                                   <a class="label label-default" href="{php echo $this->createPluginWebUrl('commission/agent',array('id' => $row['id'],'op'=>'check'))}" onclick="return confirm('确认要审核此分销商吗?')">未审核</a>
                                   {else}
                                  <span class="label label-default">未审核</span>
                                  {/if}
                                {/if}
                        {else}
                        <span class="label label-success">已审核</span>
                        {/if}
                    </td>
                    <td>注册时间：{php echo date('Y-m-d H:i',$row['createtime'])}<br/>
                        代理时间：{if !empty($row['agenttime'])}{php echo date('Y-m-d H:i',$row['agenttime'])}{/if} 
                    </td>
                       <td>  {if empty($row['followed'])}
                      {if empty($row['uid'])}
                        <label class='label label-default'>未关注</label>
                        {else}
                        <label class='label label-warning'>取消关注</label>
                        {/if}
                        {else}
                    <label class='label label-success'>已关注</label>    
                    {/if}</td>
                    <td  style="overflow:visible;">
                        
                        <div class="btn-group btn-group-sm">
                                <a class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false" href="javascript:;">操作 <span class="caret"></span></a>
                                   <ul class="dropdown-menu dropdown-menu-left" role="menu" style='z-index: 99999'>
                         {ifp 'member.member.view'}<li><a href="{php echo $this->createWebUrl('member',array('op'=>'detail', 'id' => $row['id']));}" title='会员信息'><i class='fa fa-user'></i> 会员信息</a></li>	{/if}
                                    {ifp 'commission.agent.view'}<li><a href="{php echo $this->createPluginWebUrl('commission/agent/detail',array('id' => $row['id']));}" title='详细信息'><i class='fa fa-edit'></i> 详细信息</a>	</li>	{/if}
                        {ifp 'commission.agent.order'}<li><a  href="{php echo $this->createWebUrl('order',array('op'=>'display','agentid' => $row['id']));}" title='推广订单'><i class='fa fa-list'></i> 推广订单</a></li>{/if}
                        {ifp 'commission.agent.user'}<li><a  href="{php echo $this->createPluginWebUrl('commission/agent/user',array('id' => $row['id']));}"  title='推广下线'><i class='fa fa-users'></i> 推广下线</a></li>{/if}
                        {ifp 'commission.agent.agentblack'}
                          {if $row['agentblack']==1} 
                          <li><a href="{php echo $this->createPluginWebUrl('commission/agent/agentblack',array('id' => $row['id'],'black'=>0));}" title='取消黑名单'><i class='fa fa-minus-square'></i> 取消黑名单</a></li>
                           {else}
                           <li><a href="{php echo $this->createPluginWebUrl('commission/agent/agentblack',array('id' => $row['id'],'black'=>1));}" title='设置黑名单'><i class='fa fa-minus-circle'></i> 设置黑名单</a></li>
                           {/if}
                        {/if}
                        {ifp 'commission.agent.delete'}<li><a href="{php echo $this->createPluginWebUrl('commission/agent/delete',array('id' => $row['id']));}" title="删除" onclick="return confirm('确定要删除该会员吗？');"><i class='fa fa-remove'></i> &nbsp;删除分销商</a></li>{/if}
                
                                </ul>
                            </div>

               
                    </td>
                </tr>
                {/loop}
            </tbody>
        </table>
        {$pager}
    </div>
</div>
{else if $operation=='detail'}

<form {ifp 'commission.agent.edit|commission.agent.check'}action="" method='post'{/if} class='form-horizontal'>
    <input type="hidden" name="id" value="{$member['id']}">
    <input type="hidden" name="op" value="detail">
    <input type="hidden" name="c" value="site" />
    <input type="hidden" name="a" value="entry" />
    <input type="hidden" name="m" value="sz_yi" />
    <input type="hidden" name="p" value="commission" />
    <input type="hidden" name="method" value="agent" />
    <input type="hidden" name="op" value="detail" />
    <div class='panel panel-default'>
        <div class='panel-heading'>
            分销商详细信息
        </div>
        <div class='panel-body'>

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">粉丝</label>
                <div class="col-sm-9 col-xs-12">
                    <img src='{$member['avatar']}' style='width:100px;height:100px;padding:1px;border:1px solid #ccc' />
                         {$member['nickname']}
                </div>
            </div>
           <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">OPENID</label>
                <div class="col-sm-9 col-xs-12">
                    <div class="form-control-static">{$member['openid']}</div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">真实姓名</label>
                <div class="col-sm-9 col-xs-12">
                    {ifp 'commission.agent.edit'}
                    <input type="text" name="data[realname]" class="form-control" value="{$member['realname']}"  />
                    {else}
                    <input type="hidden" name="data[realname]" class="form-control" value="{$member['realname']}"  />
                    <div class='form-control-static'>{$member['realname']}</div>
                    {/if}
                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">手机号码</label>
                <div class="col-sm-9 col-xs-12">
                       {ifp 'commission.agent.edit'}
                    <input type="text" name="data[mobile]" class="form-control" value="{$member['mobile']}"  />
                       {else}
                       <input type="hidden" name="data[mobile]" class="form-control" value="{$member['mobile']}"  />
                    <div class='form-control-static'>{$member['mobile']}</div>
                    {/if}
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">微信号</label>
                <div class="col-sm-9 col-xs-12">
                          {ifp 'commission.agent.edit'}
                    <input type="text" name="data[weixin]" class="form-control" value="{$member['weixin']}"  />
                         {else}
                         <input type="hidden" name="data[weixin]" class="form-control" value="{$member['weixin']}"  />
                    <div class='form-control-static'>{$member['weixin']}</div>
                    {/if}
                </div>
            </div>
             <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">分销商等级</label>
               <div class="col-sm-9 col-xs-12">
                         {ifp 'commission.agent.edit'}
                    <select name='data[agentlevel]' class='form-control'>
                        <option value='0'>{php echo empty($this->set['levelname'])?'普通等级':$this->set['levelname']}</option>
                         {loop $agentlevels $level}
                        <option value='{$level['id']}' {if $member['agentlevel']==$level['id']}selected{/if}>{$level['levelname']}</option>
                        {/loop}
                    </select>
                         {else}
                             <input type="hidden" name="data[agentlevel]" class="form-control" value="{$member['agentlevel']}"  />
                             
                              {if empty($member['agentlevel'])}
                            {php echo empty($this->set['levelname'])?'普通等级':$this->set['levelname']}
                                {else}
                                {php echo pdo_fetchcolumn('select levelname from '.tablename('sz_yi_commission_level').' where id=:id limit 1',array(':id'=>$member['agentlevel']))}
                                {/if}
                         {/if}
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">累计佣金</label>
                <div class="col-sm-9 col-xs-12">
                    <div class='form-control-static'> {$member['commission_total']}</div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">已打款佣金</label>
                <div class="col-sm-9 col-xs-12">
                    <div class='form-control-static'> {$member['commission_pay']}</div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">注册时间</label>
                <div class="col-sm-9 col-xs-12">
                    <div class='form-control-static'>{php echo date('Y-m-d H:i:s', $member['createtime']);}</div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">成为代理时间</label>
                <div class="col-sm-9 col-xs-12">
                    <div class='form-control-static'>{if !strexists('1970',$member['agenttime'])}{$member['agenttime']}{else}----------{/if}</div>
                </div>
            </div>
           <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">分销商权限</label>
                <div class="col-sm-9 col-xs-12">
                     {ifp 'commission.agent.check'}
                    <label class="radio-inline"><input type="radio" name="data[isagent]" value="1" {if $member['isagent']==1}checked{/if}>是</label>
                    <label class="radio-inline" ><input type="radio" name="data[isagent]" value="0" {if $member['isagent']==0}checked{/if}>否</label>
                    {else}
                      <input type='hidden' name='data[isagent]' value='{$member['isagent']}' />
                      <div class='form-control-static'>{if $member['isagent']==1}是{else}否{/if}</div>
                    {/if}
                    
                </div>
            </div>
       
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">审核通过</label>
                <div class="col-sm-9 col-xs-12">
                     {ifp 'commission.agent.check'}
                    <label class="radio-inline"><input type="radio" name="data[status]" value="1" {if $member['status']==1}checked{/if}>是</label>
                    <label class="radio-inline" ><input type="radio" name="data[status]" value="0" {if $member['status']==0}checked{/if}>否</label>
                    <input type='hidden' name='oldstatus' value="{$member['status']}" />
                       {else}
                      <input type='hidden' name='data[status]' value='{$member['status']}' />
                      <div class='form-control-static'>{if $member['status']==1}是{else}否{/if}</div>
                    {/if}
                </div>
            </div>

             <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">强制不自动升级</label>
                <div class="col-sm-9 col-xs-12">
                      {ifp 'commission.agent.edit'}
                    <label class="radio-inline" ><input type="radio" name="data[agentnotupgrade]" value="0" {if $member['agentnotupgrade']==0}checked{/if}>允许自动升级</label>
                    <label class="radio-inline"><input type="radio" name="data[agentnotupgrade]" value="1" {if $member['agentnotupgrade']==1}checked{/if}>强制不自动升级</label>
                    <span class="help-block">如果强制不自动升级，满足任何条件，此分销商的级别也不会改变</span>
                    {else}
                         <input type="hidden" name="data[agentnotupgrade]" class="form-control" value="{$member['agentnotupgrade']}"  />
                      <div class='form-control-static'>{if $member['agentnotupgrade']==1}强制不自动升级{else}允许自动升级{/if}</div>
                    {/if}
                </div>
            </div>
        
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">自选商品</label>
                <div class="col-sm-9 col-xs-12">
                      {ifp 'commission.agent.edit'}
                    <label class="radio-inline" ><input type="radio" name="data[agentselectgoods]" value="0" {if $member['agentselectgoods']==0}checked{/if}>系统设置</label>
                    <label class="radio-inline"><input type="radio" name="data[agentselectgoods]" value="1" {if $member['agentselectgoods']==1}checked{/if}>强制禁止</label>
                    <label class="radio-inline"><input type="radio" name="data[agentselectgoods]" value="2" {if $member['agentselectgoods']==2}checked{/if}>强制开启</label>
                    <span class="help-block">系统设置： 跟随系统设置，系统关闭自选则为禁止，系统开启自选则为允许</span>
                    <span class="help-block">强制禁止： 无论系统自选商品是否关闭或开启，此分销商永不能自选商品</span>
                    <span class="help-block">强制允许： 无论系统自选商品是否关闭或开启，此分销商永可以自选商品</span>
                    {else}
                      <input type="hidden" name="data[agentselectgoods]" class="form-control" value="{$member['agentselectgoods']}"  />
                      <div class='form-control-static'>{if $member['agentnotselectgoods']==1}
                          强制禁止
                          {elseif $member['agentselectgoods']==2}
                          强制允许
                          {else}
                          {if $this->set['select_goods']==1}系统允许{else}系统禁止{/if}
                          {/if}</div>
                    {/if}
                </div>
            </div>
                  <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">黑名单</label>
                <div class="col-sm-9 col-xs-12">
                       <input type='hidden' name='oldagentblack' value="{$member['agentblack']}" />
                     {ifp 'commission.agent.agentblack'}
                    <label class="radio-inline"><input type="radio" name="data[agentblack]" value="1" {if $member['agentblack']==1}checked{/if}>是</label>
                    <label class="radio-inline" ><input type="radio" name="data[agentblack]" value="0" {if $member['agentblack']==0}checked{/if}>否</label>
                       {else}
                      <input type='hidden' name='data[agentblack]' value='{$member['agentblack']}' />
                      <div class='form-control-static'>{if $member['agentblack']==1}是{else}否{/if}</div>
                    {/if}
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">备注</label>
                <div class="col-sm-9 col-xs-12">
                     {ifp 'commission.agent.edit'}
                    <textarea name="content" class='form-control'>{$member['content']}</textarea>
                       {else}
                     <textarea name="content" class='form-control' style='display:none'>{$member['content']}</textarea>
                      <div class='form-control-static'>{$member['content']}</div>
                    {/if}
                </div>
            </div>
            
            
            <div class="form-group"></div>
            <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                         {ifp 'commission.agent.edit|commission.agent.check'}
                            <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"  />
                            <input type="hidden" name="token" value="{$_W['token']}" />
                        {/if}
                       <input type="button" name="back" onclick='history.back()' {ifp 'commission.agent.edit|commission.agent.check'}style='margin-left:10px;'{/if} value="返回列表" class="btn btn-default" />
                    </div>
            </div>


        </div>


    </div>   
   
</form>

{/if}
{template 'web/_footer'}
